package com.jwds.digital.bios.business.api.controller.dispatch;

import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.DispatchRuleReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.vo.dispatch.DispatchRuleRespVO;
import com.jwds.digital.bios.business.service.service.dispatch.IDispatchRuleService;
import com.jwds.tdc.framework.application.lib.BaseResponse;
import com.jwds.tdc.framework.application.lib.page.PageRequest;
import com.jwds.tdc.framework.application.lib.page.PageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 规则内容 前端控制器
 *
 * @author 林柏云
 * @date 2024-10-24
 */
@Slf4j
@Api(tags = "规则内容")
@RestController
@RequestMapping("/dispatch/rule")
public class DispatchRuleController {

    @Resource
    private IDispatchRuleService service;

    @GetMapping("/ById/{id}")
    @ApiOperation(value = "根据id查询")
    public BaseResponse<DispatchRuleRespVO> queryById(@PathVariable("id") Long id) {
        DispatchRuleRespVO respVo = service.queryById(id);
        return BaseResponse.success(respVo);
    }

    @PostMapping("/list")
    @ApiOperation(value = "分页查询")
    public BaseResponse<PageResponse<DispatchRuleRespVO>> page(@RequestBody PageRequest<DispatchRuleReqDTO> pageRequest) {
        PageResponse<DispatchRuleRespVO> respVoPage = service.page(pageRequest);
        return BaseResponse.success(respVoPage);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增")
    public BaseResponse<?> add(@RequestBody DispatchRuleReqDTO reqDto) {
        service.add(reqDto);
        return BaseResponse.success();
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新对象")
    public BaseResponse<?> update(@RequestBody DispatchRuleReqDTO reqDto) {
        service.update(reqDto);
        return BaseResponse.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除对象")
    public BaseResponse<?> delete(@PathVariable("id") Long id) {
        service.delete(id);
        return BaseResponse.success();
    }


}
